package com.kylin.shared.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 营销策略状态
 * @author Damon S.
 * @version v1.0.1
 * @date 2020年05月30日 10:52
 */
@Getter
@RequiredArgsConstructor
public enum CampaignState {
    /**营销策略状态: 0非法值，1草稿，2已发布，3正常结束，4手动暂停，5手动结束**/
    NA(0),
    DRAFTING(1),
    PUBLISHED(2),
    FINISHED(3),
    PAUSED(4),
    STOPPED(5);

    private final int code;

    public static CampaignState parse(int code) {
        List<CampaignState> filteredStates =
                Arrays.stream(CampaignState.values())
                        .filter(state -> Objects.equals(state.getCode(), code))
                        .collect(Collectors.toList());
        return CollectionUtils.isEmpty(filteredStates) ? NA : filteredStates.get(0);
    }
}
